package com.kuaidi.config;

import com.kuaidi.entity.User;
import com.kuaidi.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

@Component
public class DataInitializer implements ApplicationRunner {
    
    @Autowired
    private UserRepository userRepository;
    
    @Override
    public void run(ApplicationArguments args) throws Exception {
        // 检查默认管理员账号是否存在
        if (!userRepository.existsByUsername("admin")) {
            User admin = new User();
            admin.setUsername("admin");
            admin.setEmail("admin@kuaidi.com");
            admin.setPassword("123456");
            userRepository.save(admin);
            System.out.println("默认管理员账号已创建: admin / 123456");
        }
    }
}

